home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / nice / nice.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-18  |  1.3 KB  |  71 lines

  1. /*
  2.  * Copyright (c) 1980 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  */
  6.  
  7. #ifndef lint
  8. char copyright[] =
  9. "@(#) Copyright (c) 1980 Regents of the University of California.\n\
  10.  All rights reserved.\n";
  11. #endif not lint
  12.  
  13. #ifndef lint
  14. static char sccsid[] = "@(#)nice.c    5.2 (Berkeley) 1/12/86";
  15. #endif not lint
  16.  
  17. #include <stdio.h>
  18.  
  19. #include <sys/time.h>
  20. #include <sys/resource.h>
  21.  
  22. #ifdef sprite
  23. #include "proc.h"
  24. #include "status.h"
  25. #endif
  26.  
  27. main(argc, argv)
  28.     int argc;
  29.     char *argv[];
  30. {
  31.     int nicarg = 10;
  32.  
  33.     if (argc > 1 && argv[1][0] == '-') {
  34.         nicarg = atoi(&argv[1][1]);
  35.         argc--, argv++;
  36.     }
  37.     if (argc < 2) {
  38.         fputs("usage: nice [ -n ] command\n", stderr);
  39.         exit(1);
  40.     }
  41. #ifndef sprite
  42.     if (setpriority(PRIO_PROCESS, 0, 
  43.         getpriority(PRIO_PROCESS, 0) + nicarg) < 0) {
  44.         perror("setpriority");
  45.         exit(1);
  46.     }
  47. #else
  48.     {
  49.         int status, prio, pid;
  50.  
  51.         pid = getpid();
  52.         status = Proc_GetPriority(pid, &prio);
  53.         if (status != 0) {
  54.             fprintf(stderr, "nice: 0x%x: %s\n", pid,
  55.                 Stat_GetMsg(status));
  56.             return (1);
  57.         }
  58.         status = Proc_SetPriority(pid, -((-prio*10)+nicarg)/10, 0);
  59.         if (status != 0) {
  60.             fprintf(stderr, "nice: 0x%x: %s\n", pid,
  61.                 Stat_GetMsg(status));
  62.             return (1);
  63.         }
  64.     }
  65. #endif
  66.  
  67.     execvp(argv[1], &argv[1]);
  68.     perror(argv[1]);
  69.     exit(1);
  70. }
  71.